package com.xghkj.yyshort

import android.os.Bundle
import com.alibaba.fplayer.flutter_aliplayer.AliChannelPool
import com.alibaba.fplayer.flutter_aliplayer.FlutterAliPlayer
import com.alibaba.fplayer.flutter_aliplayer.FlutterAliPlayerGlobalSettings
import com.alibaba.fplayer.flutter_aliplayer.FlutterAliplayerPlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import DeviceUUIDManager
class MainActivity : FlutterActivity() {
    private val CHANNEL = "alivc_environment"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        // 注册MethodChannel，名称需与Flutter端一致
        val methodChannel = MethodChannel(
            flutterEngine.dartExecutor.binaryMessenger,
            "com.example.flutter_ios_channel/method"
        )

// 设置方法调用处理器
        methodChannel.setMethodCallHandler { call, result ->
            // 处理Flutter调用的方法
            when (call.method) {
                "getDeviceUUID" -> {
                    // 获取设备UUID（这里假设KeyChainForUUID是你的UUID工具类）
                    val deviceUUID = DeviceUUIDManager.getInstance(context).getDeviceUUID()

                    // 将结果返回给Flutter
                    result.success(deviceUUID)
                }
                else -> {
                    // 处理未实现的方法
                    result.notImplemented()
                }
            }
        }


//        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
//            if (call.method == "setGlobalEnvironment") {
//                val environment = call.argument<String>("environment")
//                try {
//                    // 调用阿里云SDK的环境配置方法
//                    when (environment) {
////                        "sea" -> AlivcBase.getEnvironmentManager().setGlobalEnvironment(AlivcEnv.GlobalEnv.ENV_SEA);
////
////                        "cn" -> AlivcBase.getEnvironmentManager().setGlobalEnvironment(AlivcEnv.GlobalEnv.ENV_SEA);
//                        // 其他环境...
//                    }
//                    result.success(null)
//                } catch (e: Exception) {
//                    result.error("ERROR", "设置环境失败: ${e.message}", null)
//                }
//            } else {
//                result.notImplemented()
//            }
//        }
    }
}
